package Student;
import SuperArray.SuperArray;

import java.util.Scanner;
public class StudentUI extends Student {
    private SuperArray array = new SuperArray();
    private Scanner sc=  new Scanner(System.in);

    public StudentUI(){
        array.add(new Student("张飞","男",20));
        menu();
    }
    public void menu(){
        System.out.println("欢迎使用学生管理程序");
        while(true){
            System.out.println("请选择：1-查看所有学生 2-增加 3-修改 4-删除 5-退出");
            int input = sc.nextInt();
            if(input == 1){
                show();
            }else if(input == 2){
                add();
            }else if(input == 3){
                update();
            }else if(input == 4){
                remove();
            }else if(input == 5){
                System.exit(0);
            }
            else{
                System.out.println("输入有误");
            }
        }
    }
    public void show(){
        for (int i=0;i<array.size();i++){
            Student student=(Student)array.get(i);
            System.out.println(student.getName()+","+ student.getGender() + "," + student.getAge());
        }

    }
    public void add(){

        System.out.println("请输入学生姓名");
        setName(sc.next());
        System.out.println("请输入学生姓别");
        setGender(sc.next());
        System.out.println("请输入学生年龄");
        setAge(sc.nextInt());
        array.add(new Student(getName(),getGender(),getAge()));


    }
    public void update(){
        while(true) {
            System.out.println("请输入需要进行修改的学生姓名");
            String name = sc.next();

            for (int i = 0; i < array.size(); i++) {

                Student student = (Student) array.get(i);

                if (!student.getName().equals(name)) {
                    System.out.println("名字有误，请重新输入");
                    break;
                }else{

                System.out.println("请输入修改的学生年龄");
                int age = sc.nextInt();
                student.setAge(age);
                System.out.println("信息修改成功");
                return;}
            }

        }
    }
    public void remove(){
        while(true) {
            System.out.println("请输入需要删除的学生姓名");
            String name = sc.next();
            for (int i = 0; i < array.size(); i++) {
                Student student = (Student) array.get(i);
                if (!student.getName().equals(name)) {
                    System.out.println("名字有误，请重新输入");
                    break;
                }
                else{
                    array.remove(i);
                return;

                }
            }
        }

    }
    public static void main(String[]args){
    new StudentUI();
    }
}
